package com.hspedu.newData.dmsxl.字符串.子串匹配;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-09 
 * @Version: 1.0
 */

// todo kmp算法
public class LC28找出字符串中第一个匹配项的下标 {

    // 朴素解法
    public int strStr(String haystack, String needle) {

        char[] a = haystack.toCharArray();
        char[] b = needle.toCharArray();

        int k = 0;
        int aLen = a.length;
        int bLen = b.length;
        while (k <= aLen - bLen){
            int i = k;
            int j = 0;

            while (j<bLen && a[i]==b[j]){
                i++;
                j++;
            }
            if (j==bLen){
                return k;
            }
            k ++;
        }
        return -1;
    }


    @Test
    public void test() {
        // 测试代码


        int i = strStr("sadbutsad", "adb");
        int i1 = strStr("leetcode", "leeto");

        System.out.println("111");
    }
}
